#ifndef UTILS_H
#define UTILS_H
#define EPSILON 1e-16
#define ABSV(A) (A) > 0 ? (A) : (-(A))

bool compare_equals(double a, double b)
{
    const double absA = ABSV(a);
    const double absB = ABSV(b);
    const double diff = ABSV(a - b);

    if (a == b) {            // shortcut, handles infinities
        return true;
    } else if (a * b == 0) { // a or b or both are zero
        // relative error is not meaningful here
        return diff < EPSILON;
    } else { // use relative error
        return diff / (absA + absB) < EPSILON;
    }

}
#undef EPSILON
#undef ABSV

#endif // UTILS_H
